package com.example.demo.day.config.learn.design.proxy.p4;

import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;

import java.lang.reflect.Method;

public class FuDao implements InvocationHandler {

    private IPerson target;

    public IPerson getInstance(IPerson target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return (IPerson) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        before();
        Object result = method.invoke(this.target, objects);
        after();
        return result;
    }

    private void before() {
        System.out.println("这里是xxx辅导班，已经收到您的要求，开始挑选老师");
    }

    private void after() {
        System.out.println("双方同意，开始辅导");
    }

}
